#pragma once

#include <boost/asio.hpp>

#include "Reply.h"
#include "Request.h"
#include "RequestParser.h"


/// Represents a single synchronous connection from a client
class SimpleTcpConnection
{
public:
	/// Construct a connection with the given io_service
	SimpleTcpConnection(boost::asio::io_service &ioService);

	/// Returns underlying socket
	boost::asio::ip::tcp::socket &getSocket() { return _socket; }

	/// Starts the first synchronous operation for the connection
	void StartParsing();

private:
	/// Buffer for incoming data
	boost::array<char, 8192> _buffer;

	/// The reply to be sent back to the client
	Reply _reply;

	/// The incoming request
	Request _request;

	/// The parser for the incoming request
	RequestParser _requestParser;

	/// Socket for the connection
	boost::asio::ip::tcp::socket _socket;
};
